﻿using Furion.Logging;
using net8.Models;
using net8.Models.XiTong;
using System.Collections.Concurrent;
using System.Linq;

namespace net8.Helper
{
    public class LogHelper
    {
        public ConcurrentBag<XTLog> LogList = new ConcurrentBag<XTLog>();

        public static void Add(XTLog log)
        {
            DbHelper.Db.Insertable(log).ExecuteCommand();
        }

        public void WriteDb()
        {
            int saveCount = LogList.Count > 50 ? 50 : LogList.Count;
            List<XTLog> list = LogList.Take(saveCount).ToList();
            int result = DbHelper.Db.Insertable(list).ExecuteCommand();
            if (saveCount == result)
            {
                //foreach(XTLog log in list)
                //{
                //    LogList.TryTake(out log);
                //}

                XTLog aaa = LogList.First();
                LogList.TryTake(out aaa);

            }
            else
            {

            }
        }
    }
}
